﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BussinessLogicTecnoPez.Produccion.Producto;
using WebChart;
using System.Drawing;

public partial class Modules_Producto_PronosticoStock : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pnlResultado.Visible = false;
            TPCFechaDesde.Text = DateTime.Today.AddMonths(-5).ToShortDateString();
            TPCFechaHasta.Text = DateTime.Today.AddMonths(1).ToShortDateString();
        }

        TPPProducto.ObjType = typeof(Producto);

        GenericMasterPage master = (GenericMasterPage)this.Master;
        master.Imagen = "../Styles/Icons/wordprocessing.png";
        master.Titulo = "Informe de tendencia de stock";
    }
    protected void cmdGenerar_Click(object sender, EventArgs e)
    {
        Producto objProducto = TPPProducto.ItemSelected as Producto;
        List<StockProducto> objList = StockProducto.GetPronosticoProducto(objProducto, Convert.ToDateTime(TPCFechaDesde.Text), Convert.ToDateTime(TPCFechaHasta.Text));
        if (objList.Count == 0)
        {

        }
        ColumnChart chart1 = new ColumnChart();
        chart1.Line.Color = Color.Purple;
        chart1.Fill.Color = Color.Purple;
        chart1.LineMarker = new DiamondLineMarker(8, Color.Green, Color.Yellow);
        chart1.Legend = "Stock Real";

        ColumnChart chart2 = new ColumnChart();
        chart2.Line.Color = Color.Red;
        chart2.Fill.Color = Color.Red;
        chart2.LineMarker = new DiamondLineMarker(8, Color.Green, Color.Yellow);
        chart2.Legend = "Stock Estimado";

        foreach (StockProducto objStock in objList)
        {
            if (objStock.Fecha > DateTime.Today)
            {
                chart1.Data.Add(new ChartPoint(objStock.Fecha.ToShortDateString(), (float)0));
                chart2.Data.Add(new ChartPoint(objStock.Fecha.ToShortDateString(), (float)objStock.CantidadTotal));
            }
            else
            {
                chart1.Data.Add(new ChartPoint(objStock.Fecha.ToShortDateString(), (float)objStock.CantidadTotal));
                chart2.Data.Add(new ChartPoint(objStock.Fecha.ToShortDateString(), (float)0));
            }
        }

        charPronostico.Legend.Width = 0;
        charPronostico.Charts.Clear();
        charPronostico.Charts.Add(chart1);
        charPronostico.Charts.Add(chart2);
        ConfigureColors(charPronostico);
        charPronostico.Legend.Width = 40;
        charPronostico.RedrawChart();

        pnlResultado.Visible = true;
    }
    private void ConfigureColors(ChartControl ChartControlToSetup)
    {
        ChartControlToSetup.Background.Color = Color.FromArgb(75, Color.SteelBlue);
        ChartControlToSetup.Background.Type = InteriorType.LinearGradient;
        ChartControlToSetup.Background.ForeColor = Color.SteelBlue;
        ChartControlToSetup.Background.EndPoint = new Point(500, 350);
        ChartControlToSetup.Legend.Position = LegendPosition.Bottom;


        ChartControlToSetup.YAxisFont.ForeColor = Color.SteelBlue;
        ChartControlToSetup.XAxisFont.ForeColor = Color.SteelBlue;

        ChartControlToSetup.ChartTitle.ForeColor = Color.White;

        ChartControlToSetup.Border.Color = Color.SteelBlue;
        ChartControlToSetup.BorderStyle = BorderStyle.Ridge;
    }
}
